package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

type ArticleModel struct {
	Title   string `json:"title"`
	Content string `json:"content"`
}
type Response struct {
	Code int    `json:"code"`
	Data any    `json:"data"`
	Msg  string `json:"msg"`
}

func _getList(c *gin.Context) {
	articleList := []ArticleModel{
		{"go", "go content"},
		{"java", "java content"},
		{"js", "js content"},
	}
	c.JSON(http.StatusOK, Response{0, articleList, "success"})
}

func main() {
	r := gin.Default()
	r.GET("/getList", _getList)
	r.GET("/get", func(context *gin.Context) {
		fmt.Println("get一个请求")
		context.JSON(200, gin.H{"message": "get请求"})
	})
	r.POST("/post", func(context *gin.Context) {
		fmt.Println("post一个请求")
		context.JSON(200, gin.H{"message": "post请求"})
	})
	r.PUT("/put", func(context *gin.Context) {
		fmt.Println("put一个请求")
		context.JSON(200, gin.H{"message": "put请求"})
	})
	r.DELETE("/delete", func(context *gin.Context) {
		fmt.Println("delete一个请求")
		context.JSON(200, gin.H{"message": "delete请求"})
	})
	r.Run(":8080")
}
